package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceParamType;
import com.sailfish.springbootdemo.pojo.db1.TechDeviceParamType;
import com.sailfish.springbootdemo.service.db1.TechDeviceParamTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/techDeviceParamType")
public class TechDeviceParamTypeController {

    @Autowired
    private TechDeviceParamTypeService techDeviceParamTypeService;

    @PostMapping("/getTechDeviceParamTypeByPcbaDeviceTypeId")
    public Result getTechDeviceParamTypeByPcbaDeviceTypeId(HttpServletRequest request, Integer pcbaDeviceTypeId, String searchValue) {
        try {
            return ResultUtil.success(techDeviceParamTypeService.getTechDeviceParamTypeByPcbaDeviceTypeId(request, pcbaDeviceTypeId, searchValue));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deleteTechDeviceParamType")
    public Result deletePcbaDeviceParamType(Integer techDeviceParamTypeId) {
        return techDeviceParamTypeService.deleteTechDeviceParamType(techDeviceParamTypeId);
    }

    @PostMapping("/addOrUpdateTechDeviceParamType")
    public Result addOrUpdatePcbaDeviceParamType(String mode, TechDeviceParamType techDeviceParamType) {
        return techDeviceParamTypeService.addOrUpdateTechDeviceParamType(mode, techDeviceParamType);
    }
}
